package com.bjpowernode.boss.convert;

import com.bjpowernode.boss.domain.PayProduct;
import com.bjpowernode.boss.enums.buz.PublicStatus;
import com.bjpowernode.boss.mvc.model.vo.DitOptionVo;
import com.bjpowernode.boss.mvc.model.vo.MatchPayProductVo;
import com.bjpowernode.boss.mvc.model.vo.PayProductVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

import java.util.List;

/**
 *
 */
@Mapper(componentModel = "spring")
public interface PayProductConvert {

    // List<payProduct>  ------>  list<payproductvo>
    List<PayProductVo> toConvertPayProductvoList(List<PayProduct> payProductList);

    // List<PayProduct> -------->   List<DitOptionVo>
    List<DitOptionVo> toConvertDitOptionVoList(List<PayProduct> payProductList);

    // list<payproduct>  ---------->  list<matchpayproductvo>
    List<MatchPayProductVo> toConvertmppvList(List<PayProduct> payProductList);


    // payProduct  --->  payproductvo
    @Mappings({
            @Mapping(source = "editTime" , target = "editTime" , dateFormat = "yyyy-MM-dd HH:mm:ss"),
            @Mapping(source = "status" , target = "status" , qualifiedByName = "handleStatusConvert")
    })
    PayProductVo toCovertPayProductVo(PayProduct payProduct);

    @Named("handleStatusConvert")
    default String handleStatusConvert(String status) {
        // 定义一个新的status  --> 启用
        String newStatus = PublicStatus.ENABLE.getMsg();
        // 判断 ENABLE
        if (!PublicStatus.ENABLE.name().equals(status)){
            // 不相等 ,
            newStatus = PublicStatus.DISABLE.getMsg();
        }
        // 返回的是 启用 | 禁用
        return newStatus;
    }

    // PayProduct  ----->   payProductoptionvo
    @Mappings({
            @Mapping(source = "productCode" , target = "code"),
            @Mapping(source = "productName" , target = "label")
    })
    DitOptionVo toConvertDitOptionVo(PayProduct payProduct);

    // payproduct ----------->  matchpayproductvo
    MatchPayProductVo toConvertmppv(PayProduct payProduct);

}
